Water.shader 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. Shader "FlatKit/Water"
  2. {
  3. Properties
  4. {
  5. [KeywordEnum(Linear, Gradient Texture)] _ColorMode ("[FOLDOUT(Colors){9}]Source{Colors}", Float) = 0.0
  6. _ColorShallow ("[_COLORMODE_LINEAR]Shallow", Color) = (0.35, 0.6, 0.75, 0.8) // Color alpha controls opacity
  7. _ColorDeep ("[_COLORMODE_LINEAR]Deep", Color) = (0.65, 0.9, 1.0, 1.0)
  8. [NoScaleOffset] _ColorGradient("[_COLORMODE_GRADIENT_TEXTURE]Gradient", 2D) = "white" {}
  9. _FadeDistance("Shallow Depth", Float) = 0.5
  10. _WaterDepth("Gradient Size", Float) = 5.0
  11. _LightContribution("Light Color Contribution", Range(0, 1)) = 0
  12. _WaterClearness("Transparency", Range(0, 1)) = 0.3
  13. _ShadowStrength("Shadow Strength", Range(0, 1)) = 0.35
  14. _CrestColor("[FOLDOUT(Crest){3}]Color{Crest}", Color) = (1.0, 1.0, 1.0, 0.9)
  15. _CrestSize("Size{Crest}", Range(0, 1)) = 0.1
  16. _CrestSharpness("Sharp transition{Crest}", Range(0, 1)) = 0.1
  17. [KeywordEnum(None, Round, Grid, Pointy)] _WaveMode ("[FOLDOUT(Wave Geometry){6}]Shape{Wave}", Float) = 1.0
  18. _WaveSpeed("[!_WAVEMODE_NONE]Speed{Wave}", Float) = 0.5
  19. _WaveAmplitude("[!_WAVEMODE_NONE]Amplitude{Wave}", Float) = 0.25
  20. _WaveFrequency("[!_WAVEMODE_NONE]Frequency{Wave}", Float) = 1.0
  21. _WaveDirection("[!_WAVEMODE_NONE]Direction{Wave}", Range(-1.0, 1.0)) = 0
  22. _WaveNoise("[!_WAVEMODE_NONE]Noise{Wave}", Range(0, 1)) = 0.25
  23. [KeywordEnum(None, Gradient Noise, Texture)] _FoamMode ("[FOLDOUT(Foam){12}]Source{Foam}", Float) = 1.0
  24. [NoScaleOffset] _NoiseMap("[_FOAMMODE_TEXTURE]Texture{Foam}", 2D) = "white" {}
  25. _FoamColor("[!_FOAMMODE_NONE]Color{Foam}", Color) = (1, 1, 1, 1)
  26. [Space]
  27. _FoamDepth("[!_FOAMMODE_NONE]Shore Depth{Foam}", Float) = 0.5
  28. _FoamNoiseAmount("[!_FOAMMODE_NONE]Shore Blending{Foam}", Range(0.0, 1.0)) = 1.0
  29. [Space]
  30. _FoamAmount("[!_FOAMMODE_NONE]Amount{Foam}", Range(0, 3)) = 0.25
  31. [Space]
  32. _FoamScale("[!_FOAMMODE_NONE]Scale{Foam}", Range(0, 3)) = 1
  33. _FoamStretchX("[!_FOAMMODE_NONE]Stretch X{Foam}", Range(0, 10)) = 1
  34. _FoamStretchY("[!_FOAMMODE_NONE]Stretch Y{Foam}", Range(0, 10)) = 1
  35. [Space]
  36. _FoamSharpness("[!_FOAMMODE_NONE]Sharpness{Foam}", Range(0, 1)) = 0.5
  37. [Space]
  38. _FoamSpeed("[!_FOAMMODE_NONE]Speed{Foam}", Float) = 0.1
  39. _FoamDirection("[!_FOAMMODE_NONE]Direction{Foam}", Range(-1.0, 1.0)) = 0
  40. _RefractionFrequency("[FOLDOUT(Refraction){4}]Frequency", Float) = 35
  41. _RefractionAmplitude("Amplitude", Range(0, 0.1)) = 0.01
  42. _RefractionSpeed("Speed", Float) = 0.1
  43. _RefractionScale("Scale", Float) = 1
  44. /*
  45. _SpecularAmount("[FOLDOUT(Specular){2}]Amount{Specular}", Range(0, 1)) = 0.5
  46. [HDR] _SpecularColor("Color{Specular}", Color) = (1, 1, 1, 1)
  47. */
  48. [HideInInspector] [ToggleOff] _Opaque("Opaque", Float) = 0.0
  49. [HideInInspector] _QueueOffset("Queue offset", Float) = 0.0
  50. }
  51. SubShader
  52. {
  53. Tags
  54. {
  55. "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent"
  56. }
  57. LOD 200
  58. Blend SrcAlpha OneMinusSrcAlpha
  59. Lighting Off
  60. ZWrite[_ZWrite]
  61. HLSLINCLUDE
  62. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl"
  63. ENDHLSL
  64. Pass
  65. {
  66. HLSLPROGRAM
  67. #pragma prefer_hlslcc gles
  68. #pragma target 2.0
  69. #pragma shader_feature_local _COLORMODE_LINEAR _COLORMODE_GRADIENT_TEXTURE
  70. #pragma shader_feature_local _FOAMMODE_NONE _FOAMMODE_GRADIENT_NOISE _FOAMMODE_TEXTURE
  71. #pragma shader_feature_local _WAVEMODE_NONE _WAVEMODE_ROUND _WAVEMODE_GRID _WAVEMODE_POINTY
  72. // -------------------------------------
  73. // Universal Pipeline keywords
  74. #if VERSION_GREATER_EQUAL(11, 0)
  75. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
  76. #else
  77. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
  78. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
  79. #endif
  80. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  81. #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
  82. #pragma multi_compile _ SHADOWS_SHADOWMASK
  83. #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
  84. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  85. #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
  86. #if VERSION_GREATER_EQUAL(12, 0)
  87. #pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3
  88. #pragma multi_compile_fragment _ _LIGHT_LAYERS
  89. #pragma multi_compile_fragment _ _LIGHT_COOKIES
  90. #endif
  91. #if UNITY_VERSION >= 202220 && UNITY_VERSION < 600000
  92. #pragma multi_compile _ _FORWARD_PLUS
  93. #pragma multi_compile_fragment _ _WRITE_RENDERING_LAYERS
  94. #endif
  95. #if UNITY_VERSION >= 600000
  96. #pragma multi_compile _ _FORWARD_PLUS
  97. #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
  98. #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl"
  99. #endif
  100. // -------------------------------------
  101. // Unity defined keywords
  102. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  103. #pragma multi_compile _ LIGHTMAP_ON
  104. #pragma multi_compile_fog
  105. #if UNITY_VERSION >= 202220
  106. #pragma multi_compile _ DYNAMICLIGHTMAP_ON
  107. #pragma multi_compile_fragment _ DEBUG_DISPLAY
  108. #pragma multi_compile_fragment _ LOD_FADE_CROSSFADE
  109. #endif
  110. //--------------------------------------
  111. // GPU Instancing
  112. #pragma multi_compile_instancing
  113. #pragma instancing_options renderinglayer
  114. #pragma multi_compile _ DOTS_INSTANCING_ON
  115. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  116. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
  117. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
  118. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  119. #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesFunctions.hlsl"
  120. #pragma vertex vert
  121. #pragma fragment frag
  122. #if defined(_COLORMODE_GRADIENT_TEXTURE)
  123. TEXTURE2D(_ColorGradient);
  124. SAMPLER(sampler_ColorGradient);
  125. #endif
  126. TEXTURE2D(_NoiseMap);
  127. SAMPLER(sampler_NoiseMap);
  128. CBUFFER_START(UnityPerMaterial)
  129. float _FadeDistance, _WaterDepth;
  130. half _LightContribution;
  131. half _WaveFrequency, _WaveAmplitude, _WaveSpeed, _WaveDirection, _WaveNoise;
  132. half _WaterClearness, _CrestSize, _CrestSharpness, _ShadowStrength;
  133. half4 _CrestColor;
  134. half4 _FoamColor;
  135. half _FoamDepth, _FoamAmount, _FoamScale, _FoamSharpness, _FoamStretchX, _FoamStretchY, _FoamSpeed,
  136. _FoamDirection, _FoamNoiseAmount, _RefractionFrequency, _RefractionAmplitude, _RefractionSpeed,
  137. _RefractionScale, _FresnelAmount, _FresnelSharpness, _SunReflection;
  138. /*
  139. half _SpecularAmount;
  140. half4 _SpecularColor;
  141. */
  142. float4 _NoiseMap_ST;
  143. // _COLORMODE_LINEAR:
  144. half4 _ColorShallow, _ColorDeep;
  145. // _COLORMODE_GRADIENT_TEXTURE:
  146. float4 _ColorGradient_ST;
  147. CBUFFER_END
  148. struct VertexInput
  149. {
  150. float4 positionOS : POSITION;
  151. float2 texcoord : TEXCOORD0;
  152. float3 normalOS : NORMAL;
  153. float4 tangentOS : TANGENT;
  154. UNITY_VERTEX_INPUT_INSTANCE_ID
  155. };
  156. struct VertexOutput
  157. {
  158. float4 positionHCS : SV_POSITION;
  159. float3 positionWS : TEXCOORD6;
  160. float2 uv : TEXCOORD0;
  161. float4 screenPosition : TEXCOORD1;
  162. float waveHeight : TEXCOORD2;
  163. float3 normal : TEXCOORD3; // World space.
  164. float3 viewDir : TEXCOORD4; // World space.
  165. half fogFactor : TEXCOORD5;
  166. UNITY_VERTEX_INPUT_INSTANCE_ID
  167. UNITY_VERTEX_OUTPUT_STEREO
  168. };
  169. float2 GradientNoise_Dir(float2 p)
  170. {
  171. // Permutation and hashing used in webgl-nosie goo.gl/pX7HtC
  172. // 3d0a9085-1fec-441a-bba6-f1121cdbe3ba
  173. p = p % 289;
  174. float x = (34 * p.x + 1) * p.x % 289 + p.y;
  175. x = (34 * x + 1) * x % 289;
  176. x = frac(x / 41) * 2 - 1;
  177. return normalize(float2(x - floor(x + 0.5), abs(x) - 0.5));
  178. }
  179. float GradientNoise(float2 UV, float Scale)
  180. {
  181. const float2 p = UV * Scale;
  182. const float2 ip = floor(p);
  183. float2 fp = frac(p);
  184. const float d00 = dot(GradientNoise_Dir(ip), fp);
  185. const float d01 = dot(GradientNoise_Dir(ip + float2(0, 1)), fp - float2(0, 1));
  186. const float d10 = dot(GradientNoise_Dir(ip + float2(1, 0)), fp - float2(1, 0));
  187. const float d11 = dot(GradientNoise_Dir(ip + float2(1, 1)), fp - float2(1, 1));
  188. fp = fp * fp * fp * (fp * (fp * 6 - 15) + 10);
  189. return lerp(lerp(d00, d01, fp.y), lerp(d10, d11, fp.y), fp.x) + 0.5;
  190. }
  191. inline float DepthFade(float2 uv, VertexOutput i)
  192. {
  193. const float is_ortho = unity_OrthoParams.w;
  194. const float is_persp = 1.0 - unity_OrthoParams.w;
  195. const float depth_packed = SampleSceneDepth(uv);
  196. // Separately handles orthographic and perspective cameras.
  197. const float scene_depth = lerp(_ProjectionParams.z, _ProjectionParams.y, depth_packed) * is_ortho +
  198. LinearEyeDepth(SampleSceneDepth(uv), _ZBufferParams) * is_persp;
  199. const float surface_depth = lerp(_ProjectionParams.z, _ProjectionParams.y, i.screenPosition.z) *
  200. is_ortho + i.screenPosition.w * is_persp;
  201. const float water_depth = scene_depth - surface_depth;
  202. return saturate((water_depth - _FadeDistance) / _WaterDepth);
  203. }
  204. inline float SineWave(float3 pos, float offset)
  205. {
  206. return sin(
  207. offset + _Time.z * _WaveSpeed + (pos.x * sin(offset + _WaveDirection * PI) + pos.z *
  208. cos(offset + _WaveDirection * PI)) * _WaveFrequency);
  209. }
  210. inline float WaveHeight(float2 texcoord, float3 position)
  211. {
  212. float s = 0;
  213. #if !defined(_WAVEMODE_NONE)
  214. float2 noise_uv = texcoord * _WaveFrequency;
  215. float noise01 = GradientNoise(noise_uv, 1.0);
  216. float noise = (noise01 * 2.0 - 1.0) * _WaveNoise;
  217. s = SineWave(position, noise);
  218. #if defined(_WAVEMODE_GRID)
  219. s *= SineWave(position, HALF_PI + noise);
  220. #endif
  221. #if defined(_WAVEMODE_POINTY)
  222. s = 1.0 - abs(s);
  223. #endif
  224. #endif
  225. return s;
  226. }
  227. inline void AdditionalLights(float3 WorldPosition, out half3 Color, out half Attenuation) {
  228. Color = 0;
  229. Attenuation = 0;
  230. #ifdef _ADDITIONAL_LIGHTS
  231. const half4 shadowMask = half4(1, 1, 1, 1);
  232. const uint numAdditionalLights = GetAdditionalLightsCount();
  233. for (uint lightI = 0; lightI < numAdditionalLights; lightI++) {
  234. Light light = GetAdditionalLight(lightI, WorldPosition, shadowMask);
  235. Color += light.color;
  236. Attenuation += light.distanceAttenuation * light.shadowAttenuation;
  237. }
  238. Attenuation = saturate(Attenuation);
  239. #endif
  240. }
  241. VertexOutput vert(VertexInput i)
  242. {
  243. #if defined(CURVEDWORLD_IS_INSTALLED) && !defined(CURVEDWORLD_DISABLED_ON)
  244. #ifdef CURVEDWORLD_NORMAL_TRANSFORMATION_ON
  245. CURVEDWORLD_TRANSFORM_VERTEX_AND_NORMAL(i.positionOS, i.normalOS, i.tangentOS)
  246. #else
  247. CURVEDWORLD_TRANSFORM_VERTEX(i.positionOS)
  248. #endif
  249. #endif
  250. VertexOutput o = (VertexOutput)0;
  251. UNITY_SETUP_INSTANCE_ID(i);
  252. UNITY_TRANSFER_INSTANCE_ID(i, o);
  253. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  254. // Vertex animation.
  255. const float3 originalPositionWS = TransformObjectToWorld(i.positionOS.xyz);
  256. const float s = WaveHeight(i.texcoord, originalPositionWS);
  257. o.waveHeight = s;
  258. o.positionWS = originalPositionWS;
  259. o.positionWS.y += s * _WaveAmplitude;
  260. o.positionHCS = TransformWorldToHClip(o.positionWS);
  261. o.screenPosition = ComputeScreenPos(o.positionHCS);
  262. o.uv = i.texcoord;
  263. {
  264. // Normals.
  265. const float3 viewDirWS = GetCameraPositionWS() - o.positionWS;
  266. o.viewDir = viewDirWS;
  267. const VertexNormalInputs normalInput = GetVertexNormalInputs(i.normalOS, i.tangentOS);
  268. const float sample_distance = 0.01;
  269. float3 pos_tangent = originalPositionWS + normalInput.tangentWS * sample_distance;
  270. pos_tangent.y += WaveHeight(i.texcoord, pos_tangent) * _WaveAmplitude;
  271. float3 pos_bitangent = originalPositionWS + normalInput.bitangentWS * sample_distance;
  272. pos_bitangent.y += WaveHeight(i.texcoord, pos_bitangent) * _WaveAmplitude;
  273. const float3 modified_tangent = pos_tangent - o.positionWS;
  274. const float3 modified_bitangent = pos_bitangent - o.positionWS;
  275. const float3 modified_normal = cross(modified_tangent, modified_bitangent);
  276. o.normal = normalize(modified_normal);
  277. }
  278. const half fogFactor = ComputeFogFactor(o.positionHCS.z);
  279. o.fogFactor = fogFactor;
  280. return o;
  281. }
  282. half4 frag(VertexOutput i) : SV_TARGET
  283. {
  284. UNITY_SETUP_INSTANCE_ID(i);
  285. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
  286. // Refraction.
  287. const float2 noise_uv_refraction = i.uv * _RefractionFrequency + _Time.zz * _RefractionSpeed;
  288. const float noise01_refraction = GradientNoise(noise_uv_refraction, _RefractionScale);
  289. const float noise11_refraction = noise01_refraction * 2.0f - 1.0f;
  290. const float2 screen_uv = i.screenPosition.xy / i.screenPosition.w;
  291. const float depth_fade_original = DepthFade(screen_uv, i);
  292. float2 displaced_uv = screen_uv + noise11_refraction * _RefractionAmplitude * depth_fade_original;
  293. float depth_fade = DepthFade(displaced_uv, i);
  294. if (depth_fade <= 0.0f) // If above water surface.
  295. {
  296. displaced_uv = screen_uv;
  297. depth_fade = DepthFade(displaced_uv, i);
  298. }
  299. const half3 scene_color = SampleSceneColor(displaced_uv);
  300. half3 c = scene_color;
  301. // Water depth.
  302. half4 depth_color;
  303. half4 color_shallow;
  304. #if defined(_COLORMODE_LINEAR)
  305. depth_color = lerp(_ColorShallow, _ColorDeep, depth_fade);
  306. color_shallow = _ColorShallow;
  307. #endif
  308. #if defined(_COLORMODE_GRADIENT_TEXTURE)
  309. float2 gradient_uv = float2(depth_fade, 0.5f);
  310. depth_color = SAMPLE_TEXTURE2D(_ColorGradient, sampler_ColorGradient, gradient_uv);
  311. color_shallow = SAMPLE_TEXTURE2D(_ColorGradient, sampler_ColorGradient, float2(0.0f, 0.5f));
  312. #endif
  313. c = lerp(depth_color.rgb, c, _WaterClearness * depth_color.a);
  314. // Crest.
  315. {
  316. const half c_inv = 1.0f - _CrestSize;
  317. c = lerp(c, _CrestColor.rgb,
  318. smoothstep(c_inv, saturate(c_inv + (1.0f - _CrestSharpness)),
  319. i.waveHeight) * _CrestColor.a);
  320. }
  321. // Foam.
  322. #if !defined(_FOAMMODE_NONE)
  323. float2 stretch_factor = float2(_FoamStretchX, _FoamStretchY);
  324. float noise_foam_base;
  325. #if defined(_FOAMMODE_TEXTURE)
  326. const float2 rotated_uv = i.uv * cos(_FoamDirection * PI) +
  327. float2(i.uv.y, -i.uv.x) * sin(_FoamDirection * PI);
  328. const float2 noise_uv_foam = rotated_uv * 100.0f + _Time.zz * _FoamSpeed;
  329. noise_foam_base = SAMPLE_TEXTURE2D(_NoiseMap, sampler_NoiseMap,
  330. noise_uv_foam * stretch_factor / (_FoamScale * 100.0)).r;
  331. #endif
  332. #if defined(_FOAMMODE_GRADIENT_NOISE)
  333. // This rotation is not exactly correct, but we're keeping it for backwards compatibility.
  334. const float uv_angle = atan2(i.uv.y, i.uv.x);
  335. const float cs = cos(uv_angle + _FoamDirection * PI);
  336. const float sn = sin(uv_angle + _FoamDirection * PI);
  337. const float2 rotated_uv = float2(i.uv.x * cs - i.uv.y * sn, i.uv.x * sn + i.uv.y * cs);
  338. const float2 noise_uv_foam = rotated_uv * 100.0f + _Time.zz * _FoamSpeed;
  339. noise_foam_base = GradientNoise(noise_uv_foam * stretch_factor, _FoamScale);
  340. #endif
  341. float foam_blur = 1.0 - _FoamSharpness + 1e-6;
  342. float shore_fade = saturate(depth_fade / _FoamDepth);
  343. float hard_foam_end = 0.1;
  344. float soft_foam_end = hard_foam_end + foam_blur * 0.3;
  345. float foam_shore = smoothstep(0.5 - foam_blur * 0.5, 0.5 + foam_blur * 0.5, noise_foam_base);
  346. foam_shore = saturate(smoothstep(soft_foam_end, hard_foam_end, shore_fade) +
  347. smoothstep(1, soft_foam_end, shore_fade) * foam_shore * _FoamNoiseAmount);
  348. float foam_surface = smoothstep(noise_foam_base, noise_foam_base + foam_blur, _FoamAmount);
  349. foam_surface = smoothstep(0.5 - foam_blur * 0.5, 0.5 + foam_blur * 0.5, foam_surface);
  350. float foam = saturate(foam_shore + foam_surface);
  351. c = lerp(c, _FoamColor.rgb, foam * _FoamColor.a);
  352. #endif
  353. // Shadows.
  354. #ifndef _MAIN_LIGHT_SHADOWS
  355. #define _MAIN_LIGHT_SHADOWS // Since URP 13 or 14 this is not defined by default.
  356. #endif
  357. #if defined(_MAIN_LIGHT_SHADOWS)
  358. VertexPositionInputs vertexInput = (VertexPositionInputs)0;
  359. vertexInput.positionWS = i.positionWS.xyz;
  360. float4 shadowCoord = GetShadowCoord(vertexInput);
  361. half shadowAttenutation = MainLightRealtimeShadow(shadowCoord);
  362. c = lerp(c, c * color_shallow.rgb, _ShadowStrength * (1.0h - shadowAttenutation));
  363. #endif
  364. /*
  365. // Specular.
  366. {
  367. const float3 viewDirWS = normalize(i.viewDir);
  368. const float3 normalWS = normalize(i.normal);
  369. const float3 lightDirWS = -GetMainLight().direction;
  370. const float3 halfDirWS = normalize(viewDirWS + lightDirWS);
  371. const float specular = pow(saturate(dot(normalWS, halfDirWS)), 1.0f);
  372. c = lerp(c, c * _SpecularColor.rgb, specular * _SpecularAmount);
  373. }
  374. */
  375. c *= lerp(half3(1, 1, 1), _MainLightColor.rgb, _LightContribution);
  376. #if defined(_ADDITIONAL_LIGHTS)
  377. half3 lightColor;
  378. half lightAttenuation;
  379. AdditionalLights(i.positionWS, lightColor, lightAttenuation);
  380. lightColor = lerp(half3(1, 1, 1), lightColor, _LightContribution);
  381. c += lightColor * lightAttenuation;
  382. #if !defined(_FOAMMODE_NONE)
  383. c = lerp(c, _FoamColor.rgb * lightColor, foam * _FoamColor.a * lightAttenuation);
  384. #endif
  385. #endif
  386. c = MixFog(c, i.fogFactor);
  387. return half4(c, 1);
  388. }
  389. ENDHLSL
  390. }
  391. }
  392. CustomEditor "FlatKitWaterEditor"
  393. }